using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using UnityEditor.Animations;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [CreateAssetMenu(fileName = "AnimatorGenConfigAsset", menuName = "Create Scriptable Config/Animation Generator Config")]
    [ShowOdinSerializedPropertiesInInspector]
    public class AnimatorGenConfigAsset : ScriptableObject
    {
        [SerializeField]
        public ArtModeGenType genAnimatorType;

        public string AniamtionPath = "rAnimation";

        public string Name_Idle = "idle";
        public string Name_Walk = "walk";
        public string Name_LongIdle = "longidle";
        public string Name_Run = "run";
        public string Name_Die = "die";
        public string Name_Born = "born";
        public string Name_NormalAttack = "hand_attack01";
        public string Name_JumpStart = "jump_in";
        public string Name_JumpLoop = "jump_loop";
        public string Name_JumpEnd = "jump_out";
        public string Name_TurnLeft = "Turn_L180+";
        public string Name_TurnRight = "Turn_R180+";
        [LabelText("切换到开始跳跃的过渡时间(s)")]
        public float Time_JumpStartSiwtch = 0.25f;
        [LabelText("跳跃的开始动作到循环动作的过渡时间(s)")]
        public float Time_JumpStartToLoop = 0.1f;
        [LabelText("跳跃的循环动作到结束动作的过渡时间(s)")]
        public float Time_JumpLoopToEnd = 0.1f;
        [LabelText("播放站立长时间后休闲动作的随机时间区间")]
        public Vector2 LongIdleInterval = new Vector2(5f, 8f);

        [Serializable]
        public class AniamtorCustomParam
        {
            [LabelText("参数名字")]
            public string paramName;
            [LabelText("参数类型")]
            public AnimatorControllerParameterType paramType = AnimatorControllerParameterType.Float;
        }

        [LabelText("自定义参数")]
        public List<AniamtorCustomParam> customParam;

        [Serializable]
        public class AniamtorCustomLayer
        {
            public string layerName;
            public AnimatorLayerBlendingMode blendingMode = AnimatorLayerBlendingMode.Override;
            public float defaultWeight = 1f;
        }

        /// <summary>
        /// 自定义层级
        /// </summary>
        [LabelText("自定义动画层")]
        public List<AniamtorCustomLayer> customLayer;

        [System.Flags]
        public enum AniamtorTransitionParam
        {
            None = 0
        }

        [Serializable]
        public class AniamtorCustomTransition
        {
            [LabelText("转换的目标名字")]
            public string targetName;
            [LabelText("转换参数名字")]
            public string paramName;
            [LabelText("转换参数值")]
            public float paramValue = 0f;
            [LabelText("转换参数类型")]
            public AnimatorConditionMode paramMode = AnimatorConditionMode.If;
            [LabelText("反向")]
            public bool back;
            [LabelText("转换添加限制"), Tooltip("仅有符合条件的动作state会添加此转换")]
            public EAniamtorCustomTransitionAddType addType = EAniamtorCustomTransitionAddType.All;
            [LabelText("转换时间")]
            public float duration = 0.25f;
        }

        [Flags]
        public enum EAniamtorCustomTransitionAddType
        {
            NotLoop = 1 << 0,
            Loop = 1 << 1,
            All = -1,
        }

        [Serializable]
        public class AniamtorCustomeActionPrefix
        {
            [LabelText("动画前缀名")]
            public string prefix;
            [LabelText("属于动画的层级")]
            public int layer = 0;
            [LabelText("是否替换前缀")]
            public bool isReplacePrefix;
            [LabelText("替换前缀字符")]
            public string replacePrefix;
            [LabelText("特殊的转换")]
            public List<AniamtorCustomTransition> transitions;
            [LabelText("循环动画的Param")]
            public string loopParamName;
        }

        /// <summary>
        /// 自定义动作的前缀
        /// </summary>
        [LabelText("自定义动作的前缀")]
        public List<AniamtorCustomeActionPrefix> customPrefix;


        [Serializable]
        public class AniamtorCustomeActionLoop
        {
            [LabelText("循环动画后缀名")]
            public string loopSuffixName;
            [LabelText("是否有开始到循环的动画转换")]
            public bool hasStartToLoop;
            [LabelText("开始动画替换后缀")]
            public string startRepleceSuffixName;
        }

        [LabelText("自定义动画的循环配置")]
        public List<AniamtorCustomeActionLoop> customeActionLoops;
    }
}
